using System;
using System.Collections.Generic;

using Castle.ActiveRecord;


namespace MyMovieCollection.DATA.Models
{

    [ActiveRecord/*(Cache = CacheEnum.ReadOnly)*/]
    public class Movie:ActiveRecordBase<Movie>
    {
        [Property]
        public string Name { get; set; }

        [Property]
        public int Year { get; set; }

        [Property]
        public string Poster { get; set; }
        [Property]
        public double Point { get; set; }

        [PrimaryKey(PrimaryKeyType.Increment)]
        public int ID { get; set; }
        
        [BelongsTo("MovieTypeID")]
        public MovieType Movie_Type { get; set; }

       public static IComparer<Movie> NameComparerAsc()
       {
           return  new NameComparerAscHelper();
       }



       public static IComparer<Movie> NameComparerDesc()
       {
           return new NameComparerDescHelper();
       }

       public static IComparer<Movie> PointComparerAsc()
       {
           return new PointComparerAscHelper();
       }

        public static IComparer<Movie> PointComparerDesc()
        {
            return new PointComparerDescHelper();
        }
    }

    internal class PointComparerAscHelper : IComparer<Movie>
    {

        public int Compare(Movie x, Movie y)
        {
            if (x.Point > y.Point)
            {
                return 1;
            }
            if (x.Point < y.Point)
            {
                return -1;
            }
            return 0;
        }
    }

    internal class PointComparerDescHelper : IComparer<Movie>
    {
        public int Compare(Movie x, Movie y)
        {
            if(x.Point>y.Point)
            {
                return -1;
            }
            if(x.Point<y.Point)
            {
                return 1;
            }
            return 0;
        }
    }

    internal class NameComparerDescHelper : IComparer<Movie>
    {
        public int Compare(Movie x, Movie y)
        {
            return String.Compare(x.Name, y.Name)*-1;
        }
    }

    internal class NameComparerAscHelper : IComparer<Movie>
    {
        public int Compare(Movie x, Movie y)
        {
            return String.Compare(x.Name, y.Name);
        }
    }
}